<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>后台--文章管理</title>
    <link rel="stylesheet" type="text/css" href="<?php echo isset($skin)?$skin:"";?>images/style.css" />
    <base target="_self"/>

    <script src='<?php echo isset($skin)?$skin:"";?>js/jquery.min.js'></script>
    <script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/jquery.form.min.js"></script>
    <script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/dist/dialog-min.js"></script>
    <script src="<?php echo isset($skin)?$skin:"";?>js/admin.js"></script>
    <script type="text/javascript">
        <!--
        $(document).ready(function () {
            $('.new_table tbody tr:even').addClass('h'); //奇偶变色，添加样式
        });
        //-->
    </script>
    <script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>/js/validate.js"></script>
    <script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>js/artTemplate.js"></script>
    <script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>js/artTemplate-plugin.js"></script>
    <script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>js/form.js"></script>
    <script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>js/artDialog.js"></script>
<script type="text/javascript" charset="UTF-8" src="<?php echo isset($skin)?$skin:"";?>js/iframeTools.js"></script>
<link rel="stylesheet" href="<?php echo isset($skin)?$skin:"";?>js/artdialog.css" type="text/css">
</head>
<body>
<div class="hh6"></div>
<script charset="utf-8" src="kedit/kindeditor-min.js"></script>
<script type="text/javascript">
    var editor;
    KindEditor.ready(function(K) {
        editor = K.create('textarea[name="content"]', {uploadJson: 'kdupload.php?yeslitpic=1',filterMode:false,width:'99%',height:'500px'});
        //给按钮添加click事件
    });
    $(function(){
        $(".nav a").click(function(){
            $(this).addClass("current").siblings().removeClass("current");
            $(".new_table").eq($(this).index()).removeClass("hidden").siblings(".new_table").addClass("hidden");

        });
        $("#set").click(function(){
            $(".hidden").show("slow");
        });
    });
</script>
<div class="nav">
    <div class="navc">
        <a class="current" href="javascript:void(0)">基本信息</a>
        <a href="javascript:void(0)">栏目内容</a>
    </div>
</div>
<form method="Post" action="?c=<?php echo isset($classname)?$classname:"";?>" name="k_form">
    <table class="new_table" width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
        <thead>
        </thead>
        <tbody>
        <tr>
            <td width="13%" height="30" align="right">商品名称：</td>
            <td width="87%"><input name="name" type="text" class="input400" value="<?php echo isset($oj->name)?$oj->name:"";?>" /> <span>(*)</span></td>
        </tr>
        <tr>
            <td height="30" align="right">TAG：</td>
            <td><input name="tag" type="text" value="<?php echo isset($oj->tag)?$oj->tag:"";?>" class="input400" /></td>
        </tr>
        <tr>
            <td height="30" align="right">所属分类：</td>
            <td>
                <ul class="select">
                    <?php if(is_array($catlist))  foreach($catlist as $v) { ?>
                    <li><label><input type="checkbox" value="<?php echo isset($v->cat_id)?$v->cat_id:"";?>" name="category[]" /><?php echo isset($v->cat_name)?$v->cat_name:"";?></label></li>
                    <?php }?>
                </ul></td>
        </tr>

        <tr>
            <td height="30" align="right"><p>是否上架：</p></td>
            <td><input type="checkbox" name="is_on_sale" value="1" checked="checked"> 只有上架才能销售</td>
        </tr>
        <tr>
            <td align="right">重量单位：</td><td><select class="input200 selecth60" name="weight_unit">
                    <option value="杯" <?php if($unit=='杯'){?>selected="selected"<?php }?>>杯</option>
                    <option value="张" <?php if($unit=='张'){?>selected="selected"<?php }?>>张</option>
                    <option value="个" <?php if($unit=='个'){?>selected="selected"<?php }?>>个</option>
                    <option value="1" >千克</option><option value="0.001">克</option></select></td>
        </tr>
        <tr>
            <td align="right">赠送消费积分：</td>
            <td><input class="input50" name="point" type="text" pattern="int" value="0"/></td>
        </tr>
        <tr>
            <td align="right">基本数据：</td>
            <td>
                <div class="con" style="width:200px;">
                    <table class="border_table" width="80%">
                        <thead id="goodsBaseHead"></thead>

                        <!--商品标题模板-->
                        <script id="goodsHeadTemplate" type='text/html'>
                            <tr>
                                <th>商品货号</th>
                                <%var isProduct = false;%>
                                <%for(var item in templateData){%>
                                <%isProduct = true;%>
                                <th><%=templateData[item]['name']%></th>
                                <%}%>
                                <th>库存</th>
                                <th>市场价格</th>
                                <th>销售价格</th>
                                <th>成本价格</th>
                                <th>重量(克)</th>
                                <%if(isProduct == true){%>
                                <th>操作</th>
                                <%}%>
                            </tr>
                        </script>

                        <tbody id="goodsBaseBody"></tbody>

                        <!--商品内容模板-->
                        <script id="goodsRowTemplate" type="text/html">
                            <%var i=0;%>
                            <%for(var item in templateData){%>
                            <%item = templateData[item]%>
                            <tr class='td_c'>
                                <td><input class="small" name="_goods_no[<%=i%>]" pattern="required" type="text" value="<%=item['goods_no'] ? item['goods_no'] : item['products_no']%>" /></td>
                                <%var isProduct = false;%>
                                <%var specArrayList = parseJSON(item['spec_array'])%>
                                <%for(var result in specArrayList){%>
                                <%result = specArrayList[result]%>
                                <input type='hidden' name="_spec_array[<%=i%>][]" value='{"id":"<%=result.id%>","type":"<%=result.type%>","value":"<%=result.value%>","name":"<%=result.name%>"}' />
                                <%isProduct = true;%>
                                <td>
                                    <%if(result['type'] == 1){%>
                                    <%=result['value']%>
                                    <%}else{%>
                                    <img class="img_border" width="30px" height="30px" src="/<%=result['value']%>">
                                    <%}%>
                                </td>
                                <%}%>

                                <td><input class="tiny" name="_store_nums[<%=i%>]" type="text" pattern="int" value="<%=item['store_nums']?item['store_nums']:100%>" /></td>
                                <td><input class="tiny" name="_market_price[<%=i%>]" type="text" pattern="float" value="<%=item['market_price']%>" /></td>
                                <td>
                                    <input type='hidden' name="_groupPrice[<%=i%>]" value="<%=item['groupPrice']%>" />
                                    <input class="tiny" name="_sell_price[<%=i%>]" type="text" pattern="float" value="<%=item['sell_price']%>" />
                                    <button class="btn" type="button" onclick="memberPrice(this);"><span class="adds  <%if(item['groupPrice']){%>orange<%}%>">会员组价格</span></button>
                                </td>
                                <td><input class="tiny" name="_cost_price[<%=i%>]" type="text" pattern="float" empty value="<%=item['cost_price']%>" /></td>
                                <td><input class="tiny" name="_weight[<%=i%>]" type="text" pattern="float" empty value="<%=item['weight']%>" /></td>
                                <%if(isProduct == true){%>
                                <td><a href="javascript:void(0)" onclick="delProduct(this);"><img class="operator" src="<?php echo isset($skin)?$skin:"";?>images/icon_del.gif" alt="删除" /></a></td>
                                <%}%>

                            </tr>
                            <%i++;%>
                            <%}%>
                        </script>
                    </table>
                </div>

            </td>
        </tr>
        <tr>
            <td align="right">规格：</td>
            <td>
                <button class="btn" type="button" onclick="selSpec()"><span class="adds">添加规格</span></button>
                <label>可以生成不同组合参数的货品，比如：尺码xxl+红色+长袖 衣服</label>
            </td>
        </tr>
        <tr>
            <td align="right">商品模型：</td>
            <td>
                <select class="auto" name="model_id" onchange="create_attr(this.value)">
                    <option value="0">通用类型 </option>
                    <?php if(is_array($modellist))  foreach($modellist as $v) { ?>
                    <option value="<?php echo isset($v->id)?$v->id:"";?>"><?php echo isset($v->name)?$v->name:"";?></option>
                    <?php }?>
                </select>
                <label>可以加入商品扩展属性，比如：型号，年代，款式...</label>
            </td>
        </tr>
        <tr id="properties" style="display:none">
            <td align="right">扩展属性：</td>
            <td>
                <table class="border_table1" id="propert_table">
                    <script type='text/html' id='propertiesTemplate'>
                        <%for(var item in templateData){%>
                        <%item = templateData[item]%>
                        <%var valueItems = item['value'].split(',');%>
                        <tr>
                            <th><%=item["name"]%></th>
                            <td>
                                <%if(item['type'] == 1){%>
                                <%for(var tempVal in valueItems){%>
                                <%tempVal = valueItems[tempVal]%>
                                <label class="attr"><input type="radio" name="attr_id_<%=item['id']%>" value="<%=tempVal%>" /><%=tempVal%></label>
                                <%}%>
                                <%}else if(item['type'] == 2){%>
                                <%for(var tempVal in valueItems){%>
                                <%tempVal = valueItems[tempVal]%>
                                <label class="attr"><input type="checkbox" name="attr_id_<%=item['id']%>[]" value="<%=tempVal%>"/><%=tempVal%></label>
                                <%}%>
                                <%}else if(item['type'] == 3){%>
                                <select class="auto" name="attr_id_<%=item['id']%>">
                                    <%for(var tempVal in valueItems){%>
                                    <%tempVal = valueItems[tempVal]%>
                                    <option value="<%=tempVal%>"><%=tempVal%></option>
                                    <%}%>
                                </select>
                                <%}else if(item['type'] == 4){%>
                                <input type="text" name="attr_id_<%=item['id']%>" value="<%=item['value']%>" class="normal" />
                                <%}%>
                            </td>
                        </tr>
                        <%}%>
                    </script>
                </table>
            </td>
        </tr>
        <tr>
            <td align="right">商品推荐类型：</td>
            <td>
                <label class="attr"><input name="_goods_commend[]" type="checkbox" value="1" />最新商品</label>
                <label class="attr"><input name="_goods_commend[]" type="checkbox" value="2" />特价商品</label>
                <label class="attr"><input name="_goods_commend[]" type="checkbox" value="3" />热卖商品</label>
                <label class="attr"><input name="_goods_commend[]" type="checkbox" value="4" />推荐商品</label>
            </td>
        </tr>
        <tr>
            <td>上传相册: </td>
            <td class="upload"><div id="zyupload" class="demo"></div><div id="yc"></div>
                <div id="append">
                    <?php if(is_array($photo))  foreach($photo as $v) { ?>
                    <div id="uploadList_<?php echo isset($v->id)?$v->id:"";?>" class="upload_append_list">
                        <div class="file_bar file_hover">
                            <div style="padding:5px;">
                                <p class="file_name"></p><span onclick="delImg('uploadList_<?php echo isset($v->id)?$v->id:"";?>','<?php echo isset($v->img)?$v->img:"";?>')" class="file_del" data-index="0" title="删除"></span>
                            </div>
                        </div>
                        <a style="height:100px;width:120px;" href="javascript:(void);" class="<?php if($v->img==$img){?>setImg<?php }?> imgBox" onclick="setImg(this,'<?php echo isset($v->img)?$v->img:"";?>');">
                            <div class="uploadImg">
                                <img id="uploadImage_<?php echo isset($v->id)?$v->id:"";?>" class="upload_image" src="<?php echo isset($v->img)?$v->img:"";?>">		</div>
                        </a>
                        <p id="uploadSuccess_<?php echo isset($v->id)?$v->id:"";?>" class="file_success" style="display: block;"></p></div>
                <?php }?></div>
            </td>
        </tr>
        <tr>
            <td height="35" colspan="2" align="center" ><input name="into_wz" id="submit" class="button" type="submit" value="<?php echo isset($submit)?$submit:"";?>" />
                &nbsp;<input name="" type="reset" class="button" value="重置" />
                <input name="id" type="hidden" value="<?php echo isset($oj->id)?$oj->id:"";?>" />
                <input name="oldtag" type="hidden" value="<?php echo isset($oj->tag)?$oj->tag:"";?>" />
                <input type="hidden" name="a" value="<?php echo isset($form_action)?$form_action:"";?>" />
                <input type="hidden" name="img" value="<?php echo isset($img)?$img:"";?>" />

            </td>
        </tr>
</tbody>
        </table>
    <table class="new_table hidden" width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
        <thead></thead>
        <tbody>
        <tr>
            <td height="30" align="right">关键词：</td>
            <td><input name="keywords" type="text" value="<?php echo isset($oj->keywords)?$oj->keywords:"";?>" class="input400" /></td>
        </tr>
        <tr>
            <td height="30" align="right">说明：</td>
            <td class="pb5"><textarea name="description" class="input400 textareah"><?php echo isset($oj->description)?$oj->description:"";?></textarea></td>
        </tr>
        <tr>
            <td height="30" align="right">正文：</td>
            <td class="pb5">
                <input name="remote" type="checkbox" class="np" id="remote" value="1" checked="1">
                下载远程图片和资源
                <input name="autolitpic" type="checkbox" class="np" id="autolitpic" value="1" checked="1">
                提取第一个图片为缩略图<br>
                <textarea name="content" cols="95" rows="20" ><?php echo isset($oj->con)?$oj->con:"";?></textarea></td>
        </tr>


        <tr>
            <td height="35" colspan="2" align="center" ><input name="into_wz" id="submit" class="button" type="submit" value="<?php echo isset($submit)?$submit:"";?>" />
                &nbsp;<input name="" type="reset" class="button" value="重置" />
            </td>
        </tr></tbody>
    </table>
</form>
<!-- 引用控制层插件样式 -->
<link rel="stylesheet" href="<?php echo isset($skin)?$skin:"";?>images/zyUpload.css" type="text/css">
<script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/upload/zyFile.js"></script>
<!-- 引用控制层插件 -->
<script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/upload/zyUpload.js"></script>
<!-- 引用初始化JS -->
<script type="text/javascript" src="<?php echo isset($skin)?$skin:"";?>js/upload/demo.js"></script>
<script language="javascript">
    $(document).ready(function(){
        $("#append img").bind('click',function(){
            $("#append a").removeClass('setImg');
            $(this).parents().parents().addClass('setImg');
            $("input[name=img]").val($(this).val());
        });
    });
    function setImg(ob,img){
        $(".upload_append_list a").removeClass();
        $("input[name='img']").val(img);
        ob.className="setImg";

    }
    function delImg(i,img){
        $("#"+i).hide();
        $.get("?c=goods&a=del_img", { url:img});
    }
    //创建表单实例
    var formObj = new Form('k_form');

    //默认货号
    var defaultProductNo = '<?php echo isset($defaultProductNo)?$defaultProductNo:"";?>';

    $(function()
    {
        initProductTable();

        //存在商品信息
        <?php if($goods){?>
        var goods = <?php echo isset($goods)?$goods:"";?>;
        var goodsRowHtml = template.render('goodsRowTemplate',{'templateData':[goods]});
        $('#goodsBaseBody').html(goodsRowHtml);
        formObj.init(goods);
        //模型选择
        $('[name="model_id"]').change();
        <?php }else{?>
        $('[name="_goods_no[0]"]').val(defaultProductNo);
        <?php }?>

        //存在货品信息,进行数据填充
        <?php if($product){?>
            <?php if($spec_array){?>
        var spec_array = <?php echo isset($spec_array)?$spec_array:"";?>;
        var goodsHeadHtml = template.render('goodsHeadTemplate',{'templateData':spec_array});
        $('#goodsBaseHead').html(goodsHeadHtml);
            <?php }?>

        var product    = <?php echo isset($product)?$product:"";?>;
        var goodsRowHtml = template.render('goodsRowTemplate',{'templateData':product});
        $('#goodsBaseBody').html(goodsRowHtml);
        <?php }?>

        //商品促销回填
        <?php if($goods_commend){?>
        formObj.setValue('_goods_commend[]',"<?php echo isset($goods_commend)?$goods_commend:"";?>");
        <?php }?>

        //商品分类回填
        <?php if($category){?>
        formObj.setValue('category[]',"<?php echo isset($category)?$category:"";?>");
        <?php }?>

        //商品图片的回填

    });

    //初始化货品表格
    function initProductTable()
    {
        //默认产生一条商品标题空挡
        var goodsHeadHtml = template.render('goodsHeadTemplate',{'templateData':[]});
        $('#goodsBaseHead').html(goodsHeadHtml);

        //默认产生一条商品空挡
        var goodsRowHtml = template.render('goodsRowTemplate',{'templateData':[[]]});
        $('#goodsBaseBody').html(goodsRowHtml);
    }

    //删除货品
    function delProduct(_self)
    {
        $(_self).parent().parent().remove();
        if($('#goodsBaseBody tr').length == 0)
        {
            initProductTable();
        }
    }

    //提交表单前的检查
    function checkForm()
    {
        //整理商品图片
        var goodsPhoto = [];
        $('#thumbnails img').each(function(){
            goodsPhoto.push(this.alt);
        });
        if(goodsPhoto.length > 0)
        {
            $('input[name="_imgList"]').val(goodsPhoto.join(','));
            $('input[name="img"]').val($('#thumbnails img[class="current"]').attr('alt'));
        }
        return true;
    }

    //tab标签切换
    function select_tab(curr_tab)
    {
        $("form[name='goodsForm'] > div").hide();
        $("#table_box_"+curr_tab).show();
        $("ul[name=menu1] > li").removeClass('selected');
        $('#li_'+curr_tab).addClass('selected');
    }

    /**
     * 会员价格
     * @param obj 按钮所处对象
     */
    function memberPrice(obj)
    {
        var sellPrice = $(obj).siblings('input[name^="_sell_price"]')[0].value;
        if($.isNumeric(sellPrice) == false)
        {
            alert('请先设置商品的价格再设置会员价格');
            return;
        }

        var groupPriceValue = $(obj).siblings('input[name^="_groupPrice"]');

        //用户组的价格
        art.dialog.data('groupPrice',groupPriceValue.val());

        //开启新页面
        var tempUrl = '/admin.php?c=goods&a=member_price&sell_price=@sell_price@';
        tempUrl = tempUrl.replace('@sell_price@',sellPrice);
        art.dialog.open(tempUrl,{
            id:'memberPriceWindow',
            title: '此商品对于会员组价格',
            ok:function(iframeWin, topWin)
            {
                var formObject = iframeWin.document.forms['groupPriceForm'];
                var groupPriceObject = {};
                $(formObject).find('input[name^="groupPrice"]').each(function(){
                    if(this.value != '')
                    {
                        //去掉前缀获取group的ID
                        var groupId = this.name.replace('groupPrice','');

                        //拼接json串
                        groupPriceObject[groupId] = this.value;
                    }
                });

                //更新会员价格值
                var temp = [];
                for(var gid in groupPriceObject)
                {
                    temp.push('"'+gid+'":"'+groupPriceObject[gid]+'"');
                }
                groupPriceValue.val('{'+temp.join(',')+'}');
                return true;
            }
        });
    }

    //添加规格
    function selSpec()
    {
        //货品是否已经存在
        if($('input:hidden[name^="_spec_array"]').length > 0)
        {
            alert('当前货品已经存在，无法进行规格设置。<p>如果需要重新设置规格请您手动删除当前货品</p>');
            return;
        }

        var tempUrl = '?c=goods&a=search_spec&goods_id=@goods_id@&model_id=@model_id@';
        var model_id = $('[name="model_id"]').val();
        var goods_id = $('[name="id"]').val();

        tempUrl = tempUrl.replace('@model_id@',model_id);
        tempUrl = tempUrl.replace('@goods_id@',goods_id);

        art.dialog.open(tempUrl,{
            title:'设置商品的规格',
            okVal:'保存',
            ok:function(iframeWin, topWin)
            {
                //添加的规格
                var addSpecObject = $(iframeWin.document).find('[id^="vertical_"]');
                if(addSpecObject.length == 0)
                {
                    initProductTable();
                    return;
                }

                //开始遍历规格
                var specValueData = {};
                var specData      = {};
                addSpecObject.each(function()
                {
                    $(this).find('input:hidden[name="specJson"]').each(function()
                    {
                        var json = $.parseJSON(this.value);
                        if(!specValueData[json.id])
                        {
                            specData[json.id]      = {'id':json.id,'name':json.name,'type':json.type};
                            specValueData[json.id] = [];
                        }
                        specValueData[json.id].push(json['value']);
                    });
                });
                console.info('---------------------------');
console.info(specValueData);
                console.info(specData);console.info('---------------------------');
                //生成货品的笛卡尔积
                var specMaxData = descartes(specValueData,specData);

                //从表单中获取默认商品数据
                var productJson = {};
                $('#goodsBaseBody tr:first').find('input[type="text"]').each(function(){
                    productJson[this.name.replace(/^_(\w+)\[\d+\]/g,"$1")] = this.value;
                });

                //生成最终的货品数据
                var productList = [];
                for(var i = 0;i < specMaxData.length;i++)
                {
                    var productItem = {};
                    for(var index in productJson)
                    {
                        //自动组建货品号
                        if(index == 'goods_no')
                        {
                            //值为空时设置默认货号
                            if(productJson[index] == '')
                            {
                                productJson[index] = defaultProductNo;
                            }

                            if(productJson[index].match(/(?:\-\d*)$/) == null)
                            {
                                //正常货号生成
                                productItem['goods_no'] = productJson[index]+'-'+(i+1);
                            }
                            else
                            {
                                //货号已经存在则替换
                                productItem['goods_no'] = productJson[index].replace(/(?:\-\d*)$/,'-'+(i+1));
                            }
                        }
                        else
                        {
                            productItem[index] = productJson[index];
                        }
                    }
                    productItem['spec_array'] = specMaxData[i];
                    productList.push(productItem);
                }

                //创建规格标题
                var goodsHeadHtml = template.render('goodsHeadTemplate',{'templateData':specData});
                $('#goodsBaseHead').html(goodsHeadHtml);

                //创建货品数据表格
                var goodsRowHtml = template.render('goodsRowTemplate',{'templateData':productList});
                $('#goodsBaseBody').html(goodsRowHtml);
            }
        });
    }

    //笛卡儿积组合
    function descartes(list,specData)
    {
        //parent上一级索引;count指针计数
        var point  = {};

        var result = [];
        var pIndex = null;
        var tempCount = 0;
        var temp   = [];

        //根据参数列生成指针对象
        for(var index in list)
        {
            if(typeof list[index] == 'object')
            {
                point[index] = {'parent':pIndex,'count':0}
                pIndex = index;
            }
        }

        //单维度数据结构直接返回
        if(pIndex == null)
        {
            return list;
        }

        //动态生成笛卡尔积
        while(true)
        {
            for(var index in list)
            {
                tempCount = point[index]['count'];
                temp.push({"id":specData[index].id,"type":specData[index].type,"name":specData[index].name,"value":list[index][tempCount]});
            }

            //压入结果数组
            result.push(temp);
            temp = [];

            //检查指针最大值问题
            while(true)
            {
                if(point[index]['count']+1 >= list[index].length)
                {
                    point[index]['count'] = 0;
                    pIndex = point[index]['parent'];
                    if(pIndex == null)
                    {
                        return result;
                    }

                    //赋值parent进行再次检查
                    index = pIndex;
                }
                else
                {
                    point[index]['count']++;
                    break;
                }
            }
        }
    }

    //根据模型动态生成扩展属性
    function create_attr(model_id)
    {
        $.getJSON("?c=goods&a=attribute_init",{'model_id':model_id,'random':Math.random()}, function(json)
        {
            if(json && json.length > 0)
            {
                var templateHtml = template.render('propertiesTemplate',{'templateData':json});
                $('#propert_table').html(templateHtml);
                $('#properties').show();

                //表单回填设置项
                <?php if(isset($goods_attr)){?>
                formObj.init({<?php echo isset($goods_attr)?$goods_attr:"";?>});
                <?php }?>

            }
            else
            {
                $('#properties').hide();
            }
        });
    }

    /**
     * 图片上传回调,handers.js回调
     * @param picJson => {'flag','img','list','show'}
     */
    function uploadPicCallback(picJson)
    {
        var picHtml = template.render('picTemplate',{'picRoot':picJson.img});
        $('#thumbnails').append(picHtml);

        //默认设置第一个为默认图片
        if($('#thumbnails img[class="current"]').length == 0)
        {
            $('#thumbnails img:first').addClass('current');
        }
    }

    /**
     * 设置商品默认图片
     */
    function defaultImage(_self)
    {
        $('#thumbnails img').removeClass('current');
        $(_self).addClass('current');
    }

    /**
     *分解名称关键词
     */
    function wordsPart()
    {
        var goodsName = $('input[name="name"]').val();
        if(goodsName)
        {
            $.getJSON("?c=goods&a=goods_tags_words",{"content":goodsName},function(json)
            {
                if(json.result == 'success')
                {
                    $('input[name="search_words"]').val(json.data);
                }
            });
        }
    }

    //开始采集商品详情
    function collectAct()
    {
        var collectUrl  = $('#collectUrl').val();

        if(!collectUrl)
        {
            alert("请选择采集器并且填写完整的商品详情页URL网址");
            return;
        }

        $.getJSON("/index.php?controller=goods&action=collect_goods_detail",{"collectUrl":collectUrl},function(json)
        {
            if(json.result == 'success')
            {
                KindEditorObj.html(json.data);
                KindEditorObj.sync();
            }
            else
            {
                alert(json.msg);
            }
        });
    }
</script>

<script type="text/javascript">
    <!--
    $(document).ready(function () {
        $('.new_table tbody tr:even').addClass('h'); //奇偶变色，添加样式
    });
    //-->
</script>
</body>
</html>